<template>
  <div class="password_container">
    <div class="password_step">
      <el-steps direction="vertical" :active="active" finish-status="success">
        <el-step title="步骤 1" description="填写手机验证码"></el-step>
        <el-step title="步骤 2" description="填写新密码"></el-step>
        <el-step title="步骤 3" description="修改成功"></el-step>
      </el-steps>
    </div>
    <div class="password_box">
      <img src="@/assets/background/mango_avatar.jpg" class="avatar_box" />
      <el-form class="password_form" :model="passwordForm" :rules="rules" ref="passwordForm">
        <div v-show="0 === activeNum">
          <el-form-item prop="phone">
            <el-input v-model="passwordForm.phone" placeholder="请输入手机号" prefix-icon="el-icon-user"></el-input>
          </el-form-item>
          <el-form-item prop="verifyCode">
            <el-input class="verfyInput" v-model="passwordForm.verifyCode" placeholder="请输入验证码" prefix-icon="el-icon-message"></el-input>
            <el-button @click="sendVerify" class="verfyBtn" type="primary">发送验证码</el-button>
          </el-form-item>
        </div>
        <div v-show="1 === activeNum" class="pwdShow">
          <el-form-item prop="password">
            <el-input v-model="passwordForm.password" type="password" placeholder="请输入密码，长度限制 6 ~ 16 位">
              <template slot="prepend">新密码</template>
            </el-input>
          </el-form-item>
          <el-form-item prop="confirmPwd">
            <el-input v-model="passwordForm.confirmPwd" type="password" placeholder="请输入确认密码，与密码保持一致">
              <template slot="prepend">确认密码</template>
            </el-input>
          </el-form-item>
        </div>
        <el-form-item>
          <el-button @click="next" type="primary" class="findBtn" :disabled="isClick">{{pwdBtn}}</el-button>
        </el-form-item>
      </el-form>
      <el-link type="info" @click="goLogin" class="login_link">返回登录</el-link>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      activeNum: 0,
      isClick: false,
      pwdBtn: '重置密码',
      passwordForm: {
        phone: '13120867934',
        verifyCode: '937464',
        password: '123456',
        confirmPwd: '123456'
      },
      rules: {
        phone: [
          { pattern: /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\d{8}$/, message: '请输入正确手机号', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    goLogin() {
      this.$router.push('/login')
    },
    sendVerify() {
      setTimeout(() => {

      }, 10000)
    },
    next() {
      this.active++
      if (this.active === 1) {
        this.isClick = true
        this.pwdBtn = '确认验证码中...'
        setTimeout(() => {
          this.$message({
            message: '验证码正确，请输入您的新密码',
            type: 'success',
            center: true,
            offset: 250,
            duration: 1000,
            onClose: () => {
              this.activeNum++
            }
          })
          this.isClick = false
          this.pwdBtn = '修改密码'
        }, 2000)
      } else if (this.active === 2) {
        this.isClick = true
        this.pwdBtn = '修改密码中...'
        setTimeout(() => {
          this.$message({
            message: '修改成功，即将返回登录页面',
            type: 'success',
            center: true,
            offset: 250,
            duration: 1000,
            onClose: () => {
              this.$router.push('/login')
            }
          })
          this.isClick = false
          this.pwdBtn = '重置密码'
        }, 2000)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.password_container {
  background-color: #f4f5f7;
  height: 100%;
}

.password_step {
  position: relative;
  height: 500px;
  width: 30%;
  left: 20%;
  top: 12%;
}

.password_box {
  width: 450px;
  height: 350px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  .avatar_box {
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
}
.password_form {
  position: absolute;
  bottom: 15%;
  width: 100%;
  padding: 0 80px;
  box-sizing: border-box;

  .verfyInput {
    width: 55%;
  }

  .verfyBtn {
    position: relative;
    left: 6%;
  }

  .findBtn {
    position: relative;
    width: 80%;
    left: 10%;
    right: 10%;
    transform: translateY(10px);
  }

  .pwdShow {
    position: relative;
    width: 100%;
  }
}

.login_link {
  position: absolute;
  right: 6%;
  bottom: 6%;
}
</style>
